package com.example.lenovo.guide.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.example.lenovo.guide.Listener.WeatherListener;
import com.example.lenovo.guide.R;
import com.example.lenovo.guide.bean.WeatherInfo;
import com.example.lenovo.guide.mode.WeatherMode;

public class MainActivity extends AppCompatActivity
        implements View.OnClickListener,WeatherListener {

    EditText edit_cityNumber;
    Button button_ZH, button_51;
    TextView text_cityName, text_temp;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    void initView() {
        edit_cityNumber = (EditText) findViewById(R.id.edit_cityNumber);
        button_ZH = (Button) findViewById(R.id.button_ZH);
        button_51 = (Button) findViewById(R.id.button_51);
        text_cityName = (TextView) findViewById(R.id.text_cityName);
        text_temp = (TextView) findViewById(R.id.text_temp);
        button_ZH.setOnClickListener(this);
        button_51.setOnClickListener(this);
    }

    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.button_ZH:
                WeatherMode mode=new WeatherMode();
                mode.getWeather(edit_cityNumber.getText().toString(),this);
                break;
            case R.id.button_51:
                break;
        }


    }

    public void onResponse(WeatherInfo weatherInfo) {
       text_cityName.setText(weatherInfo.getCity());
       text_temp.setText(weatherInfo.getTemp());
    }

    @Override
    public void onFailure(String msg) {

    }
}
